//
//  UIImage+Category.m
//  Teleport
//
//  Created by xtjun on 2020/5/25.
//  Copyright © 2020 xxt. All rights reserved.
//

#import "UIImage+Category.h"

@implementation UIImage (Category)


- (void)asynImageSize:(CGSize)size color:(UIColor *)color
         finishiBlock:(void (^)(UIImage *))finishiBlock {
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
        [color setFill];
        CGRect rect = CGRectMake(0, 0, size.width, size.height);
        UIRectFill(rect);
        [self drawInRect:rect];
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        dispatch_async(dispatch_get_main_queue(), ^{
            if (finishiBlock) finishiBlock(newImage);
        });
    });
}

- (UIImage *)imageChangeColor:(UIColor *)color {
    UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);
    [color setFill];
    CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height);
    UIRectFill(bounds);
    [self drawInRect:bounds blendMode:kCGBlendModeOverlay alpha:1.0f];
    [self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}



@end
